package com.gzdh.dishrecognition.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.dhkj.web.idf.model.Product;
import com.gzdh.dishrecognition.R;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Flowable;

public class ShowFoodsCardDialog extends Dialog {

    private Map<Integer, Product> productsMap = new HashMap<>();
    private Context mContext;

    public ShowFoodsCardDialog(@NonNull Context context) {
        super(context, R.style.CustomDialog);
    }

    private Window window = null;
    TextView nameTv;
    TextView priceTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this.getContext();

        setContentView(R.layout.dialog_foods_card);
        //点击dialog以外的空白处是否隐藏
//        setCanceledOnTouchOutside(false);
        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();
        //设置窗口显示
        windowDeploy();
    }

    public TextView getNameTv() {
        return nameTv;
    }

    public void setNameTv(TextView nameTv) {
        this.nameTv = nameTv;
    }

    public TextView getPriceTv() {
        return priceTv;
    }

    public void setPriceTv(TextView priceTv) {
        this.priceTv = priceTv;
    }

    private void initView() {
        nameTv = findViewById(R.id.nameTv);
        priceTv = findViewById(R.id.priceTv);
        findViewById(R.id.closeBut).setOnClickListener(view -> {
            dismiss();
        });
    }

    private void initData() {
        Flowable.intervalRange(0, 2, 0, 1, TimeUnit.SECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext((aLong -> {


                }))
                .doOnComplete(() -> dismiss())
                .subscribe();
    }


    private void initEvent() {

    }

    private void windowDeploy() {
        window = getWindow();
//        window.setGravity(Gravity.CENTER); //设置窗口显示位置
//        window.setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画
    }

}
